<?php
/**
 * Notes:
 * Created by PhpStorm.
 * Author: TS
 * Date: 2019/10/4
 * Time: 18:35
 */

namespace app\index\controller;


use app\model\Departments;

class Department
{
    public function add(){
        if(request()->isPost()){
            $data = request()->only('name');
            $data['user_id'] = 1;
            $department = new Departments();
            if($department->addDepartment($data)){
                return res(1,'添加成功');
            }
            return res(0,'添加失败');
        }
        return res(0,'请求方式错误');
    }
    public function del($id){
        if(request()->isPost()){
            $department = new Departments();
            if($department->delDepartment($id)){
                return res(1,'删除成功');
            }
            return res(0,'删除失败');
        }
        return res(0,'请求方式错误');
    }
    public function edit(){
        if(request()->isPost()){
            $data = request()->only('name,department_id');
            if(isset($data['department_id'])){
                $id = $data['department_id'];
                unset($data['department_id']);
                $department = new Departments();
                if($department->edit($id,$data)){
                    return res(1,'修改成功');
                }
                return res(0,'修改失败');
            }
            return res(0,'缺少标识');
        }
        return res(0,'请求方式错误');
    }



}